<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
  <meta name="generator" content=
  "HTML Tidy for Linux/x86 (vers 1 September 2005), see www.w3.org">

  <title>merge</title>
  <link href="../cppreference.css" rel="stylesheet" type="text/css">
</head>

<body>
<table>
  <tr>
  <td>
  <div class="body-content">

  <div class="header-box">
    <a href="../index.html">cppreference.com</a> &gt; <a href=
    "index.html">C++ Algorithms</a> &gt; <a href="merge.html">merge</a>
  </div>

  <div class="name-format">
    merge
  </div>

  <div class="syntax-name-format">
    Syntax:
  </div>
  <pre class="syntax-box">
  #include &lt;algorithm&gt;
  iterator merge( iterator start1, iterator end1, iterator start2, iterator end2, iterator result );
  iterator merge( iterator start1, iterator end1, iterator start2, iterator end2, iterator result, StrictWeakOrdering cmp );
</pre>

  <p>The merge() function combines two sorted ranges
  [<em>start1</em>,<em>end1</em>) and [<em>start2</em>,<em>end2</em>)
  into a single sorted range, stored starting at <em>result</em>. The
  return value of this function is an iterator to the end of the merged
  range.</p>

  <p>If the strict weak ordering function object <em>cmp</em> is given,
  then it is used in place of the &lt; operator to perform comparisons
  between elements.</p>

  <p>merge() runs in <a href="../complexity.html">linear time</a>.</p>

  <div class="related-name-format">
    Related topics:
  </div>

  <div class="related-content">
    <a href="inplace_merge.html">inplace_merge</a><br>
    <a href="set_union.html">set_union</a><br>
    <a href="sort.html">sort</a>
  </div>
  </div>
  </td>
  


  </tr>
  </table>
</body></html>
